package com.ag.work2.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transaction;

import org.hibernate.Session;
import org.springframework.stereotype.Service;

import com.ag.admin.dao.TbUserDAO;
import com.ag.admin.utils.UserUtil;
import com.ag.bean.TbEvent;
import com.ag.bean.TbEventLevel;
import com.ag.bean.TbEventPlan;
import com.ag.bean.TbPropose;
import com.ag.bean.TbProposeRecord;
import com.ag.bean.TbUser;
import com.ag.bean.TbUserDept;
import com.ag.bean.TbUserRole;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.lzm.dao.BaseDAO;
import com.ag.lzm.dao.TbEventDAO;
import com.ag.lzm.dao.TbPlanDAO;
import com.ag.lzm.dao.TbRoleDAO;
import com.ag.lzm.dao.TbUserRoleDAO;
import com.ag.lzw.common.AutoAddTask;
import com.ag.work2.dao.TbEventLevelDAO;
import com.ag.work2.dao.TbEventPlanDAO;
import com.ag.work2.dao.TbEventStatusDAO;
import com.ag.work2.dao.TbProposeDAO;
import com.ag.work2.dao.TbProposeRecordDAO;
import com.ag.work2.dao.TbUserDeptDAO;
import com.ag.work2.service.IReportService;
import com.ag.work2.service.User2Dept;
import com.ag.zhh.service.ContactLogService;
import com.ag.zhh.service.EventStatusService;

@Service("LZMReportServiceImpl")
public class ReportServiceImpl implements IReportService {
	@Resource(name = "LZMTbProposeDAO")
	private TbProposeDAO proposeDAO;
	@Resource(name = "LZMBaseDAO")
	private BaseDAO baseDAO;
	@Resource(name = "LZMTbEventDAO")
	private TbEventDAO eventDAO;
	@Resource(name = "LZMTbProposeRecordDAO")
	private TbProposeRecordDAO proposeRecordDAO;
	@Resource(name = "LZMTbEventStatusDAO")
	private TbEventStatusDAO eventStatusDAO;
	@Resource(name = "iDServiceImpl")
	private IIDService idService;
	@Resource(name = "LZMTbEventPlanDAO")
	private TbEventPlanDAO eventPlanDAO;
	@Resource(name = "LZMTbPlanDAO")
	private TbPlanDAO planDAO;
	@Resource(name = "LZMTbEventLevelDAO")
	private TbEventLevelDAO eventLevelDAO;
	@Resource(name = "LZMTbUserDeptDAO")
	private TbUserDeptDAO userDeptDAO;
	// @Resource(name = "LZMTbDeptDAO")
	// private TbDeptDAO deptDAO;
	/**
	 * 短信接口
	 */
	@Resource(name = "ContactLogService")
	private ContactLogService contactLogService;
	/**
	 * 用户角色DAO
	 */
	@Resource(name = "LZMTbUserRoleDAO")
	private TbUserRoleDAO userRoleDAO;
	/**
	 * 角色DAO
	 */
	@Resource(name = "LZMTbRoleDAO")
	private TbRoleDAO roleDAO;
	/**
	 * 用户DAO
	 */
	@Resource(name = "LZMTbUserDAO")
	private TbUserDAO userDAO;
	/**
	 * 任务下发
	 */
	@Resource(name = "AutoAddTask")
	private AutoAddTask addTask;

	@Override
	public TbPropose findEventPropose(String EId) {
		// String queryString =
		// "from TbPropose p join fetch p.tbProposeRecords join fetch p.tbEvent e "
		// +
		// "join fetch e.tbEventSource join fetch p.tbUserByPViceCommander join fetch p.tbUserByPTeamLeader "
		// +
		// "join fetch p.tbUserByPCommander join fetch p.tbUserDeptByPImplementPlan join fetch p.tbUserDeptByPAssistDept "
		// + "where e.EId = ?";
		// String queryString =
		// "from TbPropose p join fetch p.tbProposeRecords pr join fetch pr.tbUserByPrId.tbUserDepts join fetch p.tbEvent e "
		// +
		// "join fetch e.tbEventSource join fetch p.tbUserByPViceCommander join fetch p.tbUserByPTeamLeader "
		// +
		// "join fetch p.tbUserByPCommander join fetch p.tbUserDeptByPImplementPlan join fetch p.tbUserDeptByPAssistDept "
		// + "where e.EId = ?";
		String queryString = "from TbPropose p join fetch p.tbProposeRecords pr join fetch pr.tbUserByPrId prub join fetch prub.tbUserDepts join fetch prub.tbUserRoles urrr join fetch urrr.tbRole "
				+ "join fetch pr.tbUserByPrCheckId prubpc join fetch prubpc.tbUserDepts "
				+
				// "join fetch pr.tbUserByPrId.tbUserRoles.tbRole join fetch p.tbEvent e "
				"join fetch p.tbEvent e "
				+ "join fetch e.tbEventSource "
				+ "where e.EId = ? order by pr.b";// desc";
		// <<<<<<< .mine
		// List<TbPropose> list = baseDAO.find(queryString, EId);
		// if(list == null || list.size() < 1){
		// return null;
		// }
		// return list.get(0);
		// =======
		List list = baseDAO.find(queryString, EId);
		if (list != null && list.size() != 0) {
			return (TbPropose) list.get(0);
		}
		return null;
		// return (TbPropose) baseDAO.find(queryString, EId).get(0);
		// >>>>>>> .r824
		// List list=baseDAO.find(queryString,EId);
		// System.out.println(list==null);
		// System.out.println(list.size());
		// return (TbPropose) list.get(0);
		// //return new TbPropose();
	}

	@Override
	public String findEventStatusByID(String EId) {
		return eventDAO.findById(EId).getTbEventStatus().getTbesId();
	}

	@Override
	public void savePropose(TbPropose propose, TbProposeRecord proposeRecord,
			TbUser user) {
		// 呈批记录ID
		String cpjlidString = idService.findTablePK(IDUtil.TB_PROPOSE_RECORD);
		propose.setPpId(idService.findTablePK(IDUtil.TB_PROPOSE));
		/**
		 * 呈批人信息 为了同意下级提供条件
		 */
		if (proposeRecord.getTbUserByPrCheckId() != null
				&& !proposeRecord.getTbUserByPrCheckId().getUId().isEmpty()) {
			propose.setA(proposeRecord.getTbUserByPrCheckId().getUId());
		}
		propose.setB(user.getUId());
		propose.setC(null);
		propose.setD(cpjlidString);
		proposeDAO.save(propose);
		TbEvent e = eventDAO.findById(propose.getTbEvent().getEId());
		e.setTbEventStatus(eventStatusDAO
				.findById(EventStatusService.EVENT_STATUS_YJCHP_ING));
		eventDAO.attachDirty(e);
		// 呈批记录
		proposeRecord.setNewPpId(cpjlidString);
		proposeRecord.setTbUserByPrId(user);
		if (proposeRecord.getTbUserByPrCheckId() == null
				|| proposeRecord.getTbUserByPrCheckId().getUId().isEmpty()) {
			proposeRecord.setTbUserByPrCheckId(user);
		}else {
//			propose.setA(proposeRecord.getTbUserByPrCheckId().getUId());
			proposeRecord.setTbUserByPrCheckId(proposeRecord.getTbUserByPrCheckId());
		}
		proposeRecord.setTbPropose(propose);
		proposeRecord.setB(getCurrentTime());
		// proposeRecord.setPaTime(new Date());
		proposeRecordDAO.save(proposeRecord);
		/**
		 * 调用短信接口
		 */
		String smsContent = "有"+e.getEEventname()+"事件待呈批处理，请登录系统查看，谢谢！";

		TbUser dst = userDAO.findById(proposeRecord.getTbUserByPrCheckId()
				.getUId());

		// System.out.println("proposeRecord.getTbUserByPrCheckId().getUPhone()"+
		// proposeRecord
		// .getTbUserByPrCheckId().getUPhone());
		contactLogService.addOneMessageContactLogByEvent(user.getUName(), dst
				.getUName(), dst.getUId(), dst.getUPhone(), smsContent, propose
				.getTbEvent().getEId());

	}

	@Override
	public TbEvent findEventByID(String EId) {
		String queryString = "from TbEvent e join fetch e.tbEventSource join fetch e.tbEventLevel join fetch e.tbEventStatus where e.EId = ?";
		return (TbEvent) baseDAO.find(queryString, EId).get(0);
	}

	@Override
	public void saveProposeRecord(TbPropose propose,
			TbProposeRecord proposeRecord, TbUser user) {
		// propose.setPpId(idService.findTablePK(IDUtil.TB_PROPOSE));
		// proposeDAO.save(propose);
		TbEvent e = eventDAO.findById(propose.getTbEvent().getEId());

		Integer currentES = Integer.parseInt(e.getTbEventStatus().getTbesId());
		/**
		 * 判断事件状态
		 */
		// if (currentES==1002) {
		//			
		// }
		if (currentES.equals(Integer
				.valueOf(EventStatusService.EVENT_STATUS_SJJB))
				|| currentES.equals(Integer
						.valueOf(EventStatusService.EVENT_STATUS_SJSHL))) {
			// String qing = "from TbPropose p where p.tbEvent.EId = ?";
			// proposeDAO.delete((TbPropose) baseDAO.find(qing, EId).get(0));
			savePropose(propose, proposeRecord, user);
			return;
		}
		/**
		 * 判断事件状态结束
		 */
		// e.set
		// Long tmp = Long.valueOf(tablePK);
		// ids.setIdValues((++tmp).toString());

		// e.setTbEventStatus(eventStatusDAO.findById((++currentES).toString()));
		// eventDAO.attachDirty(e);
		// 呈批记录
		String cpjlidString = idService.findTablePK(IDUtil.TB_PROPOSE_RECORD);
		proposeRecord.setNewPpId(cpjlidString);
		proposeRecord.setTbUserByPrId(user);

		TbPropose propose4save = proposeDAO.findById(propose.getPpId());

		proposeRecord.setTbPropose(propose4save);
		proposeRecord.setB(getCurrentTime());
		// proposeRecord.setPaTime(new Date());
		proposeRecordDAO.save(proposeRecord);
		// 修改为当前呈批主权
		// propose4save.setB(propose4save.getA());
		// propose4save.setA(user.getUId());
		propose4save.setA(proposeRecord.getTbUserByPrCheckId().getUId());
		propose4save.setB(user.getUId());
		propose4save.setC(null);
		propose4save.setD(cpjlidString);
		proposeDAO.attachDirty(propose4save);
		/**
		 * 保存审批短信日志
		 */
		TbUser dst = userDAO.findById(proposeRecord.getTbUserByPrCheckId()
				.getUId());
		// System.out.println("proposeRecord.getTbUserByPrCheckId().getUPhone()"+
		// proposeRecord
		// .getTbUserByPrCheckId().getUPhone());
		String smsContent = "有"+e.getEEventname()+"事件待呈批处理，请登录系统查看，谢谢！";
		contactLogService.addOneMessageContactLogByEvent(user.getUName(), dst
				.getUName(), dst.getUId(), dst.getUPhone(), smsContent, propose
				.getTbEvent().getEId());

	}

	private String getCurrentTime() {
		SimpleDateFormat localTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return localTime.format(new Date());
	}

	@Override
	public void startPlan(String EId, String PId, TbUser user) {
		String queryString = "select count(*) from TbEventPlan ep where ep.EId = ?";
		Long rst = (Long) baseDAO.find(queryString, EId).get(0);
		if (rst != 0) {
			String tm = "delete from TbEventPlan ep where ep.EId = '" + EId
					+ "'";
			try {
				baseDAO.operate(tm);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// TbEventPlan eventPlan = new TbEventPlan();
		// eventPlan.setTbPlan(planDAO.findById(PId));
		// eventPlan.setTbEvent(eventDAO.findById(EId));
		// eventPlanDAO.save(eventPlan);
		TbEventPlan eventPlan = new TbEventPlan();
		eventPlan.setEId(EId);
		eventPlan.setTbPlan(planDAO.findById(PId));
		eventPlan.setTbUserByEpPeople(user);
		eventPlan.setEpReason("启动预案");
		eventPlan.setEpTime(new Date());
		eventPlanDAO.save(eventPlan);
		// String smsContent = "正在启动预案！";
		// contactLogService.addOneMessageContactLogByEvent(user.getUName(),
		// proposeRecord.getTbUserByPrCheckId().getUName(), proposeRecord
		// .getTbUserByPrCheckId().getUId(), proposeRecord
		// .getTbUserByPrCheckId().getUPhone(), smsContent,
		// propose.getTbEvent().getEId());
		// /**
		// * 保存审批短信日志
		// */
		// String smsContent = "有药害事件待呈批处理，请登录系统查看，谢谢！";
		// contactLogService.addOneMessageContactLogByEvent(user.getUName(),
		// proposeRecord.getTbUserByPrCheckId().getUName(), proposeRecord
		// .getTbUserByPrCheckId().getUId(), proposeRecord
		// .getTbUserByPrCheckId().getUPhone(), smsContent,
		// propose.getTbEvent().getEId());
		/**
		 * 保存审批短信日志
		 */
		TbEvent e = eventDAO.findById(EId);
		SimpleDateFormat sf44 = new SimpleDateFormat();
		String smsContent = "药害事件：" + e.getEEventname() + "已经在"
				+ sf44.format(new Date()) + "由" + user.getUName() + "启动预案";
		// TbUser rrrTbUser=userDAO.findById(UId);
		contactLogService.addOneMessageContactLogByEvent(user.getUName(), user
				.getUName(), user.getUId(), user.getUPhone(), smsContent, EId);
	}

	@Override
	public String checkEventAdmin(String EId) {
		String queryString = "select count(*) from TbProposeRecord pr where pr.tbPropose.tbUserByPViceCommander.UId is not null and "
				+ "pr.tbPropose.tbEvent.EId = ?";
		// System.out.println(queryString);
		Long rst = (Long) baseDAO.find(queryString, EId).get(0);
		// System.out.println(rst);
		if (rst == 0) {
			return "noadmin";
		}
		return "yesadmin";
	}

	@Override
	public String checkPropose(String EId) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 提交呈批时更新到呈批表
	 */
	@Override
	public void saveAdmin(TbPropose propose, String EId, TbUser user) {
		
		String queryString = "select p.ppId from TbPropose p where p.tbEvent.EId = ?";
		List list = baseDAO.find(queryString, propose.getTbEvent().getEId());
		if (list != null && list.size() != 0) {
			// System.out.println("list != null");
			// propose.setPpId((String) list.get(0));

			TbPropose tmPropose = proposeDAO.findById((String) list.get(0));

			TbEvent eaa = eventDAO.findById(EId);

			// e.setTbUserByUId(e.getTbUserByTbUId());
			// eaa.setTbUserByTbUId(tmPropose.getTbUserByPViceCommander());

			// eaa.setTbUserByUId(tmPropose.getTbUserByPViceCommander());
			// if (!propose.getTbUserByPViceCommander().getUId().isEmpty()) {
			System.out.println("--------------------------"
					+ propose.getTbUserByPViceCommander());

			// }
			// tmPropose.getTbUserByPViceCommander();
			if (propose.getTbUserByPViceCommander() != null
					&& !propose.getTbUserByPViceCommander().getUId().isEmpty()) {
				eaa.setTbUserByTbUId(propose.getTbUserByPViceCommander());
				eventDAO.attachDirty(eaa);
				tmPropose.setTbUserByPViceCommander(propose
						.getTbUserByPViceCommander());
				//System.out.println("=================更新指挥长到event============================"+eventDAO.findById(EId).getTbUserByTbUId().getUId());
			}

			if (propose.getTbUserByPCommander() != null
					&& !propose.getTbUserByPCommander().getUId().isEmpty()) {
				// propose.setTbUserByPCommander(null);
				tmPropose
						.setTbUserByPCommander(propose.getTbUserByPCommander());
			}
			if (propose.getTbUserByPTeamLeader() != null
					&& !propose.getTbUserByPTeamLeader().getUId().isEmpty()) {
				// propose.getTbUserByPTeamLeader().setUId(null);
				// propose.setTbUserByPTeamLeader(null);
				tmPropose.setTbUserByPTeamLeader(propose
						.getTbUserByPTeamLeader());
			}
			if (propose.getTbUserDeptByPAssistDept() != null
					&& !propose.getTbUserDeptByPAssistDept().getUdId()
							.isEmpty()) {
				// propose.getTbUserDeptByPAssistDept().setUdId(null);
				// propose.setTbUserDeptByPAssistDept(null);
				tmPropose.setTbUserDeptByPAssistDept(propose
						.getTbUserDeptByPAssistDept());
			}
			if (propose.getTbUserDeptByPImplementPlan() != null
					&& !propose.getTbUserDeptByPImplementPlan().getUdId()
							.isEmpty()) {
				// propose.getTbUserDeptByPAssistDept().setUdId(null);
				// propose.setTbUserDeptByPAssistDept(null);
				tmPropose.setTbUserDeptByPImplementPlan(propose
						.getTbUserDeptByPImplementPlan());
			}
			if (propose.getE() != null && !propose.getE().isEmpty()) {
				// propose.getTbUserDeptByPImplementPlan().setUdId(null);
				// propose.setTbUserDeptByPImplementPlan(null);
				// tmPropose.setTbUserDeptByPImplementPlan(propose
				// .getTbUserDeptByPImplementPlan());
				System.out.println("**********propose.getE()***************"
						+ propose.getE());
				tmPropose.setE(propose.getE());
			}

			System.out
					.println("*///////////*********************************************////i//////"
							+ tmPropose.getF());

			if (tmPropose.getF() != null && !tmPropose.getF().isEmpty()) {
				Integer i = new Integer(tmPropose.getF());
				i++;
				System.out
						.println("*///////////*********************************************////i//////"
								+ i);
				tmPropose.setF(i.toString());
			} else {
				System.out
						.println("*///////////*********************no way*****************////i//////");
				tmPropose.setF("1");
			}

			proposeDAO.attachDirty(tmPropose);

		} else {
			// System.out.println("savelist != null");
			propose.setPpId(idService.findTablePK(IDUtil.TB_PROPOSE));
			// System.out.println("savelist1 != null"+propose.getTbUserByPTeamLeader().getUId()==
			// "");
			// System.out.println("savelist1 != null"+propose.getTbUserByPTeamLeader().getUId()==
			// null);
			// System.out.println("savelist1 != null005"+propose.getTbUserByPTeamLeader().getUId().isEmpty());
			if (propose.getTbUserByPCommander().getUId() == ""
					|| propose.getTbUserByPCommander().getUId() == null
					|| propose.getTbUserByPCommander().getUId().isEmpty()) {
				propose.setTbUserByPCommander(null);
			}
			if (propose.getTbUserByPTeamLeader().getUId() == ""
					|| propose.getTbUserByPTeamLeader().getUId() == null
					|| propose.getTbUserByPTeamLeader().getUId().isEmpty()) {
				// propose.getTbUserByPTeamLeader().setUId(null);
				propose.setTbUserByPTeamLeader(null);
			}
			if (propose.getTbUserDeptByPAssistDept().getUdId() == ""
					|| propose.getTbUserDeptByPAssistDept().getUdId() == null
					|| propose.getTbUserDeptByPAssistDept().getUdId().isEmpty()) {
				// propose.getTbUserDeptByPAssistDept().setUdId(null);
				propose.setTbUserDeptByPAssistDept(null);
			}
			if (propose.getE() == "" || propose.getE() == null
					|| propose.getE().isEmpty()) {
				// propose.getTbUserDeptByPImplementPlan().setUdId(null);
				propose.setTbUserDeptByPImplementPlan(null);
			}
			propose.setF("1");
			System.out.println("**********propose.setF()************"
					+ propose.getF());
			proposeDAO.save(propose);

			TbEvent eaa = eventDAO.findById(EId);

			// e.setTbUserByUId(e.getTbUserByTbUId());
			eaa.setTbUserByTbUId(propose.getTbUserByPViceCommander());
			// eaa.setTbUserByUId(propose.getTbUserByPViceCommander());
			eventDAO.attachDirty(eaa);
		}
		/**
		 * 修改事件状态为 EVENT_STATUS_SJZHHSL = "1014";//事件指挥受理
		 */
		// /**
		// * 指挥权暂交付
		// */
		// TbUserRole ur = new TbUserRole();
		// // ur.setTbUser(propose.getTbUserByPViceCommander());
		// ur.setTbUser(userDAO.findById(propose.getTbUserByPViceCommander()
		// .getUId()));
		// ur.setTbRole(roleDAO.findById(UserUtil.VICE_COMMANDER));
		// ur.setTbEvent(eventDAO.findById(EId));
		// ur.setA("0");
		// userRoleDAO.save(ur);
		// /**
		// * 确定指挥长，自动下发任务
		// */
		// // addTask.autoTask(propose.getTbUserByPTeamLeader().getUId(),
		// propose
		// // .getTbUserDeptByPAssistDept().getUdId(), propose
		// // .getTbUserDeptByPImplementPlan().getUdId(), EId, UId);
		// /**
		// * 保存审批短信日志
		// */
		// SimpleDateFormat sf44 = new SimpleDateFormat();
		// String smsContent = "药害事件：" + e.getEEventname() + "已经在"
		// + sf44.format(new Date()) + "由" + user.getUName() + "指定"
		// + propose.getTbUserByPViceCommander().getUName() + "为指挥长";
		// // TbUser rrrTbUser=userDAO.findById(UId);
		// contactLogService.addOneMessageContactLogByEvent(user.getUName(),
		// propose.getTbUserByPViceCommander().getUName(), propose
		// .getTbUserByPViceCommander().getUId(), propose
		// .getTbUserByPViceCommander().getUPhone(), smsContent,
		// propose.getTbEvent().getEId());
	}

	/**
	 * 指定指挥长
	 */
	@Override
	public void saveAdminSoFar(TbPropose propose, String EId, TbUser user) {
		String queryString = "select p.ppId from TbPropose p where p.tbEvent.EId = ?";
		List list = baseDAO.find(queryString, propose.getTbEvent().getEId());
		if (list != null && list.size() != 0) {
			// System.out.println("list != null");
			// propose.setPpId((String) list.get(0));

			TbPropose tmPropose = proposeDAO.findById((String) list.get(0));

			TbEvent eaa = eventDAO.findById(EId);

			// e.setTbUserByUId(e.getTbUserByTbUId());
			// eaa.setTbUserByTbUId(tmPropose.getTbUserByPViceCommander());
			eaa.setTbUserByTbUId(propose.getTbUserByPViceCommander());
			// eaa.setTbUserByUId(tmPropose.getTbUserByPViceCommander());
			eventDAO.attachDirty(eaa);

			// tmPropose.getTbUserByPViceCommander();
			tmPropose.setTbUserByPViceCommander(propose
					.getTbUserByPViceCommander());

			if (!propose.getTbUserByPCommander().getUId().isEmpty()) {
				// propose.setTbUserByPCommander(null);
				tmPropose
						.setTbUserByPCommander(propose.getTbUserByPCommander());
			}
			if (!propose.getTbUserByPTeamLeader().getUId().isEmpty()) {
				// propose.getTbUserByPTeamLeader().setUId(null);
				// propose.setTbUserByPTeamLeader(null);
				tmPropose.setTbUserByPTeamLeader(propose
						.getTbUserByPTeamLeader());
			}
			if (!propose.getTbUserDeptByPAssistDept().getUdId().isEmpty()) {
				// propose.getTbUserDeptByPAssistDept().setUdId(null);
				// propose.setTbUserDeptByPAssistDept(null);
				tmPropose.setTbUserDeptByPAssistDept(propose
						.getTbUserDeptByPAssistDept());
			}
			if (!propose.getE().isEmpty()) {
				// propose.getTbUserDeptByPImplementPlan().setUdId(null);
				// propose.setTbUserDeptByPImplementPlan(null);
				// tmPropose.setTbUserDeptByPImplementPlan(propose
				// .getTbUserDeptByPImplementPlan());
				System.out.println("**********propose.getE()***************"
						+ propose.getE());
				tmPropose.setE(propose.getE());
			}

			System.out
					.println("*///////////*********************************************////i//////"
							+ tmPropose.getF());

			if (tmPropose.getF() != null && !tmPropose.getF().isEmpty()) {
				Integer i = new Integer(tmPropose.getF());
				i++;
				System.out
						.println("*///////////*********************************************////i//////"
								+ i);
				tmPropose.setF(i.toString());
			} else {
				System.out
						.println("*///////////*********************no way*****************////i//////");
				tmPropose.setF("1");
			}

			proposeDAO.attachDirty(tmPropose);

		} else {
			// System.out.println("savelist != null");
			propose.setPpId(idService.findTablePK(IDUtil.TB_PROPOSE));
			// System.out.println("savelist1 != null"+propose.getTbUserByPTeamLeader().getUId()==
			// "");
			// System.out.println("savelist1 != null"+propose.getTbUserByPTeamLeader().getUId()==
			// null);
			// System.out.println("savelist1 != null005"+propose.getTbUserByPTeamLeader().getUId().isEmpty());
			if (propose.getTbUserByPCommander().getUId() == ""
					|| propose.getTbUserByPCommander().getUId() == null
					|| propose.getTbUserByPCommander().getUId().isEmpty()) {
				propose.setTbUserByPCommander(null);
			}
			if (propose.getTbUserByPTeamLeader().getUId() == ""
					|| propose.getTbUserByPTeamLeader().getUId() == null
					|| propose.getTbUserByPTeamLeader().getUId().isEmpty()) {
				// propose.getTbUserByPTeamLeader().setUId(null);
				propose.setTbUserByPTeamLeader(null);
			}
			if (propose.getTbUserDeptByPAssistDept().getUdId() == ""
					|| propose.getTbUserDeptByPAssistDept().getUdId() == null
					|| propose.getTbUserDeptByPAssistDept().getUdId().isEmpty()) {
				// propose.getTbUserDeptByPAssistDept().setUdId(null);
				propose.setTbUserDeptByPAssistDept(null);
			}
			if (propose.getE() == "" || propose.getE() == null
					|| propose.getE().isEmpty()) {
				// propose.getTbUserDeptByPImplementPlan().setUdId(null);
				propose.setTbUserDeptByPImplementPlan(null);
			}
			propose.setF("1");
			System.out.println("**********propose.setF()************"
					+ propose.getF());
			proposeDAO.save(propose);

			TbEvent eaa = eventDAO.findById(EId);

			// e.setTbUserByUId(e.getTbUserByTbUId());
			eaa.setTbUserByTbUId(propose.getTbUserByPViceCommander());
			// eaa.setTbUserByUId(propose.getTbUserByPViceCommander());
			eventDAO.attachDirty(eaa);
		}
		// /**
		// * 修改事件状态为 EVENT_STATUS_SJZHHSL = "1014";//事件指挥受理
		// */
		// TbEvent e = eventDAO.findById(propose.getTbEvent().getEId());
		// e.setTbEventStatus(eventStatusDAO
		// .findById(EventStatusService.EVENT_STATUS_SJZHHSL));
		// eventDAO.attachDirty(e);
		// /**
		// * 指挥权暂交付
		// */
		// TbUserRole ur = new TbUserRole();
		// // ur.setTbUser(propose.getTbUserByPViceCommander());
		// ur.setTbUser(userDAO.findById(propose.getTbUserByPViceCommander()
		// .getUId()));
		// ur.setTbRole(roleDAO.findById(UserUtil.VICE_COMMANDER));
		// ur.setTbEvent(eventDAO.findById(EId));
		// ur.setA("0");
		// userRoleDAO.save(ur);
		// /**
		// * 确定指挥长，自动下发任务
		// */
		// // addTask.autoTask(propose.getTbUserByPTeamLeader().getUId(),
		// propose
		// // .getTbUserDeptByPAssistDept().getUdId(), propose
		// // .getTbUserDeptByPImplementPlan().getUdId(), EId, UId);
		// /**
		// * 保存审批短信日志
		// */
		// SimpleDateFormat sf44 = new SimpleDateFormat();
		// TbUser dst = userDAO.findById(propose.getTbUserByPViceCommander()
		// .getUId());
		// String smsContent = "药害事件：" + e.getEEventname() + "已经在"
		// + sf44.format(new Date()) + "由" + user.getUName() + "指定"
		// + propose.getTbUserByPViceCommander().getUName() + "为指挥长";
		// // TbUser rrrTbUser=userDAO.findById(UId);
		// contactLogService.addOneMessageContactLogByEvent(user.getUName(), dst
		// .getUName(), dst.getUId(), dst.getUPhone(), smsContent, propose
		// .getTbEvent().getEId());
	}

	@Override
	public void auditPropose(TbProposeRecord proposeRecord, TbUser user,
			String EId) {
		TbProposeRecord pr = proposeRecordDAO.findById(proposeRecord
				.getNewPpId());
		pr.setC(proposeRecord.getC());
		pr.setD(proposeRecord.getD());
		// pr.setPComments(proposeRecord.getPComments());
		pr.setPaTime(new Date());
		pr.setTbUserByPrCheckId(user);
		proposeRecordDAO.attachDirty(pr);
		/**
		 * 修改事件状态为 EVENT_STATUS_SJZHHSL = "1014";//事件指挥受理
		 */
		// TbEvent e =
		// eventDAO.findById(pr.getTbPropose().getTbEvent().getEId());
		//
		// TbPropose propose=pr.getTbPropose();
		// propose.getPpId()
		// TbEvent

		/*
		 * 正确代码 String tpid = pr.getTbPropose().getPpId(); String queryString =
		 * "select e from TbPropose p join fetch p.tbEvent e where p.ppId = ?";
		 * TbEvent e = (TbEvent) baseDAO.find(queryString, tpid).get(0); Integer
		 * currentES = Integer.parseInt(e.getTbEventStatus().getTbesId());
		 * e.setTbEventStatus
		 * (eventStatusDAO.findById((++currentES).toString()));
		 * eventDAO.attachDirty(e);
		 */
		TbEvent e = eventDAO.findById(EId);
		Integer currentES = Integer.parseInt(e.getTbEventStatus().getTbesId());
		e.setTbEventStatus(eventStatusDAO.findById((++currentES).toString()));
		eventDAO.attachDirty(e);
	}

	@Override
	public void ratingEvent(String EId, String elId) {
		// System.out.println(EId);
		// System.out.println(elId);
		TbEvent event = eventDAO.findById(EId);
		TbEventLevel el = eventLevelDAO.findById(elId);
		// System.out.println(el.getElId());
		event.setTbEventLevel(el);
		// System.out.println(event == null);
		eventDAO.attachDirty(event);
	}

	@Override
	public String selectExt4Command(String eventID) {
		/**
		 * 先判断事件是否处于 事件指挥受理、事件处置中
		 */
		if (eventDAO.findById(eventID).getTbEventStatus().getTbesId().equals(
				EventStatusService.EVENT_STATUS_SJZHHSL)
				|| eventDAO.findById(eventID).getTbEventStatus().getTbesId()
						.equals(EventStatusService.EVENT_STATUS_SJCHZH_ING)) {
			/**
			 * 临时预案 tmpplan
			 */
			String queryString = "select count(*) from TbEventPlan ep where ep.EId = ?";
			List list = baseDAO.find(queryString, eventID);
			if (list != null && list.size() != 0) {
				if ((Long) list.get(0) > 0) {
					return "yesplan";
				} else {
					return "noplan";
				}
			}
		}
		if (Integer.valueOf(eventDAO.findById(eventID).getTbEventStatus()
				.getTbesId()) >= Integer
				.valueOf(EventStatusService.EVENT_STATUS_SJCHZH_FINISH)) {
			return "hasdone";
		}
		return "nodone";
	}

	@Override
	public void cancelPropose(TbProposeRecord proposeRecord, String EId) {
		// TbEvent e = eventDAO.findById(EId);
		// Integer currentES =
		// Integer.parseInt(e.getTbEventStatus().getTbesId());
		// e.setTbEventStatus(eventStatusDAO.findById((--currentES).toString()));
		// eventDAO.attachDirty(e);
		// System.out.println(proposeRecord.getNewPpId() + "getNewPpId()");
		// System.out.println(proposeRecord.getNewPpId() == null);
		proposeRecordDAO.delete(proposeRecordDAO.findById(proposeRecord
				.getNewPpId()));
		// 处理按钮显示TbPropose c字段
		String qing11 = "from TbPropose p where p.tbEvent.EId = ?";
		TbPropose pre = (TbPropose) baseDAO.find(qing11, EId).get(0);
		pre.setC("1");
		proposeDAO.attachDirty(pre);
		String qing12 = "select count(*) from TbPropose p join p.tbProposeRecords where p.tbEvent.EId = ?";
		Long currentES = (Long) baseDAO.find(qing12, EId).get(0);
		if (currentES == 0) {
			String qing = "from TbPropose p where p.tbEvent.EId = ?";
			proposeDAO.delete((TbPropose) baseDAO.find(qing, EId).get(0));
			TbEvent e = eventDAO.findById(EId);
			e
					.setTbEventStatus(eventStatusDAO
							.findById((EventStatusService.EVENT_STATUS_SJJB)
									.toString()));
			eventDAO.attachDirty(e);
		}
	}

	@Override
	public void agreeLower(TbPropose propose, TbProposeRecord proposeRecord,
			TbUser user) {
		// String queryString = "from TbPropose p where p.tbEvent.EId = ?";
		// TbPropose propose = (TbPropose)baseDAO.find(queryString, EId).get(0);
		// propose.setC("1");
		// proposeDAO.attachDirty(propose);
		proposeRecord.setNewPpId(idService
				.findTablePK(IDUtil.TB_PROPOSE_RECORD));
		TbPropose propose4save = proposeDAO.findById(propose.getPpId());
		// 临时赋予权力
		proposeRecord.setTbUserByPrId(user);
		// 即同意下级动作发起者
		proposeRecord.setTbUserByPrCheckId(userDAO
				.findById(propose4save.getB()));

		proposeRecord.setTbPropose(propose4save);
		proposeRecord.setB(getCurrentTime());
		// proposeRecord.setPaTime(new Date());
		proposeRecordDAO.save(proposeRecord);
		// 修改为当前呈批主权
		// propose4save.setB(propose4save.getA());
		// propose4save.setA(user.getUId());
		// propose4save.setA(proposeRecord.getTbUserByPrCheckId().getUId());
		// propose4save.setB(user.getUId());
		propose4save.setC("1");
		proposeDAO.attachDirty(propose4save);
	}

	@Override
	public User2Dept findFirstReportPropose(String EId) {
		String qing11 = "from TbProposeRecord pr where pr.tbPropose.tbEvent.EId = ? order by pr.b asc";
		List list = baseDAO.find(qing11, EId);
		if (list == null || list.size() == 0) {
			System.out.println("gggggggggggg");
			return null;
		}
		TbProposeRecord pr = (TbProposeRecord) list.get(0);
		List<TbUser> users = new ArrayList<TbUser>();
		System.out.println(pr.getPCommander() + "pr.getPCommander())");
		System.out.println(pr.getPTeamLeader() + "pr.getPTeamLeader()");
		users.add(userDAO.findById(pr.getPCommander()));
		users.add(userDAO.findById(pr.getPTeamLeader()));
		users.add(userDAO.findById(pr.getPViceCommander()));
		List<TbUserDept> userDepts = new ArrayList<TbUserDept>();
		userDepts.add(userDeptDAO.findById(pr.getPAssistDept()));
		userDepts.add(userDeptDAO.findById(pr.getPImplementPlan()));
		User2Dept u2d = new User2Dept();
		u2d.setUserDepts(userDepts);
		u2d.setUsers(users);
		return u2d;
	}

	@Override
	public void directly(TbPropose propose, TbProposeRecord proposeRecord,
			TbUser user) 
	{
		//万才改过,保存指挥长到事件表
	//	TbEvent e1 = eventDAO.findById(propose.getTbEvent().getEId());
		
	//	e1.setTbUserByTbUId(propose.getTbUserByPViceCommander());
	//	eventDAO.attachDirty(e1);
		
		String qing12 = "select count(*) from TbPropose p where p.tbEvent.EId = ?";
		Long newid = (Long) baseDAO.find(qing12, propose.getTbEvent().getEId())
				.get(0);
		if (newid == 0) {
			String cpjlidString = idService
					.findTablePK(IDUtil.TB_PROPOSE_RECORD);
			propose.setPpId(idService.findTablePK(IDUtil.TB_PROPOSE));
			/**
			 * 呈批人信息 为了同意下级提供条件
			 */
			if (proposeRecord.getTbUserByPrCheckId() == null
					|| proposeRecord.getTbUserByPrCheckId().getUId().isEmpty()) {
				propose.setA(user.getUId());
			} else {
				propose.setA(proposeRecord.getTbUserByPrCheckId().getUId());
			}
			propose.setB(user.getUId());
			propose.setC(null);
			propose.setD(cpjlidString);// 保存最新呈批ID

			if (proposeRecord.getPCommander() != null
					&& !proposeRecord.getPCommander().isEmpty())
				propose.setTbUserByPCommander(userDAO.findByUName(
						proposeRecord.getPCommander()).get(0));
			
			if (proposeRecord.getPTeamLeader() != null
					&& !proposeRecord.getPTeamLeader().isEmpty())
				propose.setTbUserByPTeamLeader(userDAO.findByUName(
						proposeRecord.getPTeamLeader()).get(0));
			
			if (proposeRecord.getPViceCommander() != null
					&& !proposeRecord.getPViceCommander().isEmpty())
				propose.setTbUserByPViceCommander(userDAO.findByUName(
						proposeRecord.getPViceCommander()).get(0));
			
			if (proposeRecord.getPImplementPlan() != null
					&& !proposeRecord.getPImplementPlan().isEmpty())
//				propose.setTbUserDeptByPImplementPlan(userDeptDAO.findByUdName(
//						proposeRecord.getPImplementPlan()).get(0));
				propose.setE(proposeRecord.getPImplementPlan()); //E字段存协助部门信息
			
			if (proposeRecord.getPAssistDept() != null
					&& !proposeRecord.getPAssistDept().isEmpty())
				propose.setTbUserDeptByPAssistDept(userDeptDAO.findByUdName(
						proposeRecord.getPAssistDept()).get(0));
			

			proposeDAO.save(propose);
			// savePropose(propose, proposeRecord, user);
			// String cpjlidString = idService
			// .findTablePK(IDUtil.TB_PROPOSE_RECORD);
			proposeRecord.setNewPpId(cpjlidString);
			proposeRecord.setTbUserByPrId(user);
			proposeRecord.setTbUserByPrCheckId(user);

			// TbPropose propose4save = proposeDAO.findById(propose.getPpId());
			// String qing = "from TbPropose p where p.tbEvent.EId = ?";
			// TbPropose propose4save = (TbPropose)baseDAO.find(qing,
			// propose.getTbEvent().getEId()).get(0);

			proposeRecord.setTbPropose(propose);
			proposeRecord.setB(getCurrentTime());
			// proposeRecord.setPaTime(new Date());
			proposeRecordDAO.save(proposeRecord);
			// 修改为当前呈批主权
			// propose4save.setB(propose4save.getA());
			// propose4save.setA(user.getUId());

			// propose4save.setA(proposeRecord.getTbUserByPrCheckId().getUId());
			// propose4save.setB(user.getUId());
			// propose4save.setC(null);
			// propose4save.setD(cpjlidString);
			// proposeDAO.attachDirty(propose4save);
			// 修改事件状态为呈批中

			//			
			// TbEvent tmpe = eventDAO.findById(propose.getTbEvent().getEId());
			// tmpe.setTbEventStatus(eventStatusDAO
			// .findById(EventStatusService.EVENT_STATUS_YJCHP_ING));
			// eventDAO.attachDirty(tmpe);
			saveAdmin(propose, propose.getTbEvent().getEId(), user);
			TbEvent e = eventDAO.findById(propose.getTbEvent().getEId());
			e.setTbEventStatus(eventStatusDAO
					.findById(EventStatusService.EVENT_STATUS_SJZHHSL));
		
			//万才改过的地方
			e.setTbUserByTbUId(propose.getTbUserByPViceCommander());
			

			eventDAO.attachDirty(e);

			/**
			 * 往用户角色表插入记录，保存用户ID和角色ID以及事件ID
			 */
			TbUserRole ur = new TbUserRole();
			// ur.setTbUser(propose.getTbUserByPViceCommander());
			// ur.setTbUser(userDAO.findById(propose.getTbUserByPViceCommander()
			// .getUId()));
			ur.setTbUser(userDAO.findById(userDAO.findByUName(
					proposeRecord.getPViceCommander()).get(0).getUId()));
			ur.setTbRole(roleDAO.findById(UserUtil.VICE_COMMANDER));
			ur.setTbEvent(eventDAO.findById(propose.getTbEvent().getEId()));
			ur.setA("0");
			userRoleDAO.save(ur);
			/**
			 * 确定指挥长，自动下发任务
			 */
			if (propose.getTbUserByPTeamLeader() != null
					&& propose.getTbUserDeptByPAssistDept() != null
					&& propose.getTbUserDeptByPImplementPlan() != null)
				addTask.autoTask(propose.getTbUserByPTeamLeader().getUId(),
						propose.getTbUserDeptByPAssistDept().getUdId(), propose
								.getTbUserDeptByPImplementPlan().getUdId(),
						propose.getTbEvent().getEId(), user.getUId());
			/**
			 * 保存审批短信日志
			 */
			SimpleDateFormat sf44 = new SimpleDateFormat();
		String smsContent="您已被"+ user.getUName() +"任命为"+e.getEEventname()+"应急事件指挥长，请尽快处置应急事件。谢谢！";
//			String smsContent = e.getEEventname() + "已经在"
//			+ sf44.format(new Date()) + "由" + user.getUName() + "指定"
//			+ propose.getTbUserByPViceCommander().getUName() + "为指挥长";
			
			
			// TbUser rrrTbUser=userDAO.findById(UId);
			contactLogService.addOneMessageContactLogByEvent(user.getUName(),
					propose.getTbUserByPViceCommander().getUName(), propose
							.getTbUserByPViceCommander().getUId(), propose
							.getTbUserByPViceCommander().getUPhone(),
					smsContent, propose.getTbEvent().getEId());
			return;
		} else {
			String cpjlidString = idService
					.findTablePK(IDUtil.TB_PROPOSE_RECORD);
			proposeRecord.setNewPpId(cpjlidString);
			proposeRecord.setTbUserByPrId(user);
			proposeRecord.setTbUserByPrCheckId(user);

			TbPropose propose4save = proposeDAO.findById(propose.getPpId());

			proposeRecord.setTbPropose(propose4save);
			proposeRecord.setB(getCurrentTime());
			// proposeRecord.setPaTime(new Date());
			proposeRecordDAO.save(proposeRecord);
			// 修改为当前呈批主权
			// propose4save.setB(propose4save.getA());
			// propose4save.setA(user.getUId());
			if (proposeRecord.getTbUserByPrCheckId() == null
					|| proposeRecord.getTbUserByPrCheckId().getUId().isEmpty()) {
				propose4save.setA(user.getUId());
			} else {
				propose4save
						.setA(proposeRecord.getTbUserByPrCheckId().getUId());
			}
			// propose4save.setA(proposeRecord.getTbUserByPrCheckId().getUId());
			propose4save.setB(user.getUId());
			propose4save.setC(null);
			propose4save.setD(cpjlidString);

			if (proposeRecord.getPCommander() != null
					&& !proposeRecord.getPCommander().isEmpty())
				propose4save.setTbUserByPCommander(userDAO.findByUName(
						proposeRecord.getPCommander()).get(0));
			if (proposeRecord.getPTeamLeader() != null
					&& !proposeRecord.getPTeamLeader().isEmpty())
				propose4save.setTbUserByPTeamLeader(userDAO.findByUName(
						proposeRecord.getPTeamLeader()).get(0));
			if (proposeRecord.getPViceCommander() != null
					&& !proposeRecord.getPViceCommander().isEmpty())
				propose4save.setTbUserByPViceCommander(userDAO.findByUName(
						proposeRecord.getPViceCommander()).get(0));
			if (proposeRecord.getPImplementPlan() != null
					&& !proposeRecord.getPImplementPlan().isEmpty())
//				propose4save
//						.setTbUserDeptByPImplementPlan(userDeptDAO
//								.findByUdName(proposeRecord.getPImplementPlan())
//								.get(0));
			propose4save.setE(proposeRecord.getPImplementPlan()); //E字段存协助部门信息
			if (proposeRecord.getPAssistDept() != null
					&& !proposeRecord.getPAssistDept().isEmpty())
				propose4save
						.setTbUserDeptByPAssistDept(userDeptDAO.findByUdName(
								proposeRecord.getPAssistDept()).get(0));

			proposeDAO.attachDirty(propose4save);
			saveAdmin(propose, propose.getTbEvent().getEId(), user);
			TbEvent e = eventDAO.findById(propose.getTbEvent().getEId());
			//万才改过的地方，把指挥长放进事件表中
			if(propose.getTbUserByPViceCommander()!=null) e.setTbUserByTbUId(propose.getTbUserByPViceCommander());
			e.setTbEventStatus(eventStatusDAO
					.findById(EventStatusService.EVENT_STATUS_SJZHHSL));
			eventDAO.attachDirty(e);
			/**
			 * 往用户角色表插入记录，保存用户ID和角色ID以及事件ID
			 */
			TbUserRole ur = new TbUserRole();
			// ur.setTbUser(propose.getTbUserByPViceCommander());
			// ur.setTbUser(userDAO.findById(propose.getTbUserByPViceCommander()
			// .getUId()));
			ur.setTbUser(userDAO.findById(userDAO.findByUName(
					proposeRecord.getPViceCommander()).get(0).getUId()));
			ur.setTbRole(roleDAO.findById(UserUtil.VICE_COMMANDER));
			ur.setTbEvent(eventDAO.findById(propose.getTbEvent().getEId()));
			ur.setA("0");
			userRoleDAO.save(ur);
			/**
			 * 确定指挥长，自动下发任务
			 */
			if (propose4save.getTbUserByPTeamLeader() != null
					&& propose4save.getTbUserDeptByPAssistDept() != null
					&& propose4save.getTbUserDeptByPImplementPlan() != null)
				addTask.autoTask(
						propose4save.getTbUserByPTeamLeader().getUId(),
						propose4save.getTbUserDeptByPAssistDept().getUdId(),
						propose4save.getTbUserDeptByPImplementPlan().getUdId(),
						propose.getTbEvent().getEId(), user.getUId());
			/**
			 * 保存审批短信日志
			 */
			SimpleDateFormat sf44 = new SimpleDateFormat();
			String smsContent = "药害事件：" + e.getEEventname() + "已经在"
					+ sf44.format(new Date()) + "由" + user.getUName() + "指定"
					+ propose4save.getTbUserByPViceCommander().getUName() + "为指挥长";
			// TbUser rrrTbUser=userDAO.findById(UId);
			contactLogService.addOneMessageContactLogByEvent(user.getUName(),
					propose4save.getTbUserByPViceCommander().getUName(), propose4save
							.getTbUserByPViceCommander().getUId(), propose4save
							.getTbUserByPViceCommander().getUPhone(),
					smsContent, propose.getTbEvent().getEId());
			// 修改事件状态为呈批中
			// TbEvent tmpe = eventDAO.findById(propose.getTbEvent().getEId());
			// tmpe.setTbEventStatus(eventStatusDAO
			// .findById(EventStatusService.EVENT_STATUS_YJCHP_ING));
			// eventDAO.attachDirty(tmpe);
		}
	//	System.out.println("\n\n\n\n\n\n\n\n\n\n事件的指挥长： "+propose.getTbUserByPViceCommander().getUId()+"\n"+propose.getTbUserByPViceCommander().getUName());
		
		/**
		 * 判断事件状态结束
		 */
		// e.set
		// Long tmp = Long.valueOf(tablePK);
		// ids.setIdValues((++tmp).toString());

		// e.setTbEventStatus(eventStatusDAO.findById((++currentES).toString()));
		// eventDAO.attachDirty(e);
		// 呈批记录

		/**
		 * 保存审批短信日志
		 */
		// String smsContent = "有药害事件待呈批处理，请登录系统查看，谢谢！";
		// contactLogService.addOneMessageContactLogByEvent(user.getUName(),
		// proposeRecord.getTbUserByPrCheckId().getUName(), proposeRecord
		// .getTbUserByPrCheckId().getUId(), proposeRecord
		// .getTbUserByPrCheckId().getUPhone(), smsContent,
		// propose.getTbEvent().getEId());
		
		//万才改过的地方，保存指挥长到事件表
		Session session = proposeDAO.getSessionFactory().openSession();
		org.hibernate.Transaction tx = session.beginTransaction();
		TbPropose propse2 = (TbPropose) session.get(TbPropose.class, propose.getPpId());
		System.out.println("指挥长："+propse2.getTbUserByPViceCommander().getUId()+"\n"+propse2.getTbUserByPViceCommander().getUName());
		TbEvent e3 = (TbEvent) session.get(TbEvent.class, propose.getTbEvent().getEId());
		e3.setTbUserByTbUId(propse2.getTbUserByPViceCommander());
		System.out.println("事件："+e3.getEId()+"  指挥长："+e3.getTbUserByTbUId().getUId());
		session.saveOrUpdate(e3);
		tx.commit();
		session.close();

	}

}
